<template>
  <div class="mTop">
    <div class="wCen">
      <div class="mTop_l">
        <div class="logo">
          <a :href="localeCn ? '/' : '/en'"><img src="@/assets/img/logo.svg" alt="" class="img" /></a>
        </div>
         <!-- 倒计时 -->
         <common-countdown />
      </div>
      <div class="mTop_r">
        <!-- 各个icon -->
        <div class="icons" :class="localeCn ? '' : 'en'">
          <!-- 中英文切换 -->
          <common-lang :width="50"/>
          <!-- 搜索 -->
          <div class="search" @click.stop="showSearchBox">
            <img src="@/assets/images/icon_search-white.png" :alt="$t('search')" class="img" v-if="isHome"/>
            <img src="@/assets/images/icon_search.png" :alt="$t('search')" class="img" v-else/>
            <!-- 搜索弹框 -->
            <div class="searchModal" :class="isShowSearch ? 'isShow' : ''">
              <div class="searchBox">
                <img src="@/assets/img/icon_arrow_right.svg" class="close" @click.stop="hideSearchBox" />
                <span class="line">|</span>
                <el-input v-model="keyword" :placeholder="$t('placeholder-search')" class="inp" v-show="isShowSearch" clearable maxlength="50" minlength="1" @change="search" @clear="clear"></el-input>
                <img src="@/assets/img/icon_search.svg" class="searchBtn" @click.stop="search" />
              </div>
            </div>
          </div>
          <!-- 用户信息 -->
          <div class="user" @mouseover="showMenu = true" @mouseleave="showMenu = false">
            <img src="@/assets/images/icon_avatar-white.png" alt="" class="img" v-if="isHome"/>
            <img src="@/assets/images/icon_avatar.png" alt="" class="img" v-else/>
            <div v-if="showMenu" @mouseleave="showMenu = false">
              <common-float-menu />
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mask" v-if="isShowSearch" @click.stop="hideSearchBox"></div>
  </div>
</template>

<script>
export default {
  props: {},
  data() {
    return {
      keyword: "",
      showMenu: false,
    };
  },
  computed: {
    isShowSearch() {
      return this.$store.state.data.isShowSearch;
    },
  },
  mounted() {},
  methods: {
    // 搜索
    search() {
      if (!this.keyword) {
        this.$message({
          message: this.$t("search-tip"),
          type: "error",
        });
        return;
      }
      let routeUrl = this.$router.resolve({
        path: this.localeCn ? `/search` : "/en/search",
        query: {
          keyword: this.keyword,
        },
      });
      window.open(routeUrl.href, "_blank");
    },
    clear() { 
      this.keyword = ''
      this.hideSearchBox()
    }
  },
};
</script>

<style lang="scss" scoped>
.mTop {
  // 顶部搜索栏的遮罩
  .mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9;
    background-color: rgba(0, 0, 0, 0.12);
  }
  // 搜索弹框
  .searchModal {
    $gutter: -10px;
    right: 0;
    top: $gutter;
    position: absolute;
    z-index: 99;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-radius: 2px;
    height: 60px;
    width: 0;
    overflow: hidden;
    padding-left: 0;
    transition: all 0.2s linear;

    // 显示搜索弹框
    &.isShow {
      width: 750px;
      padding-left: 50px;
    }

    .searchBox {
      display: flex;
      width: 100%;
      align-items: center;
      padding-right: 50px;

      :deep(.el-input__inner) {
        color: #191e33;
        height: 50px;
        font-size: 16px;
        border: none;
      }

      .close {
        width: 20px;
        cursor: pointer;
        margin-right: 20px;
      }

      .line {
        margin: 0 16px 0 8px;
        color: #191e33;
      }

      // 搜索按钮
      .searchBtn {
        width: 20px;
        cursor: pointer;
        margin-left: 40px;
      }
    }
  }
  .logo {
    $g:35px;
    $w:calc(154px + #{$g});
    display: flex;
    align-items: center;
    flex-direction: column;
    width: $w;
    flex: 0 0 $w;
    position: relative;
    border-right:1px solid rgba(0,0,0,0.1);
    padding-right: $g;
    margin-right: $g;

    .img {
      max-width: 100%;
      max-height: 100%;
    }
  }
  // 各个icon 搜索 手机端 语言 用户信息
  .icons {
    display: flex;
    align-items: center;
    height: 100%;

    // 搜索
    .search,
    .icons_mobile,
    .lang,
    .user {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 0px;
      height: 100%;

      .img {
        $w: 30px;
        width: $w;
        flex: 0 0 $w;
      }
    }

    .user {
      position: relative;
    }

    .search {
      position: relative;
      cursor: pointer;
      margin: 0 50px;
    }
  }
  .wCen {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 140px;
    overflow: visible;
  }
  &_l {
    display: flex;
    justify-content: flex-start;
  }
  @media (min-width:1441px) and (max-width: 1750px) {
    .wCen{
      height: 120px;
    }
  }
  @media screen and (min-width: 1281px) and (max-width: 1440px) {
    .wCen{
      height: 110px;
    }
  }
  @media screen and (min-width: 768px) and (max-width: 1280px) {
    .wCen{
      height: 110px;
      .icons{
        .search,
        .icons_mobile,
        .lang,
        .user {
          width: auto;
        }
      }
    }
  }
  @media (max-width: 767px) {}

  @media (min-width: 768px) and (max-width: 1560px) {
    .logo {
      flex: 0 0 150px;

      .txt {
        font-size: 12px;
        position: relative;
        top: -10px;
      }
    }
    // 各个icon 搜索 手机端 语言 用户信息
    .icons {
      .search,
      .icons_mobile,
      .lang,
      .user {
        width: 30px;

        .img {
          $w: 26px;
          width: $w;
          flex: 0 0 $w;
        }
      }
      &_mobile {
        .codeBox {
          top: 100px;
        }
      }
    }

    .searchModal {
      $gutter: 20px;
      top: $gutter;
      height: calc(100% - 20px * 2);
      // 显示搜索弹框
      &.isShow {
        width: 650px;
      }
    }
  }
}
</style>
